<?php 
	class Msg
	{
		private $list;
		private $db;

		function __construct ()
		{
			include_once('db.php');
			$this->db = new DB();
		}
		function listRow($page,$pagesize,$option,$url)
		{
			if(empty($option)){
				$option = true;
			}
			//获得留言的总数
			$sql1 = "select * from guest where $option";
			$count = $this->db->getCount($sql1);
			//计算分页数
			$count = ceil($count/$pagesize);

			//查询第page页的内容
			$pagecount = ($page-1)*$pagesize;
			$sql = "select * from guest where $option limit $pagecount,$pagesize";
			$this->list = $this->db->get($sql);

			//显示留言结果 
 			for ($i=1; $i <= count($this->list); $i++) 
 			{ 
 				$str = $this->list[$i-1][4];
 				$id = $this->list[$i-1][0];
 				echo "<li>留言内容$i:$str<a href='modify.php?act=update&id=$id'>修改</a> <a href='modify.php?act=del&id=$id'>删除</a></li>";
 			} 
 			//显示分页
 			echo "共{$count}页 当前是第{$page}页 ";

 			for($i=1;$i<=$count;$i++){
				if($page == $i){
					echo $i;
				}else{			
					echo "<a href='$url?page=$i'>[$i]</a>";
				}
			}
		}
		function message($arr,$uid)
		{
			$uid = $uid?$uid:0;
			$email = $arr['email'];
			$content = $arr['content'];
			$ctime = time();
			$sql = "insert into guest values
			(null,'$uid',null,'$email','$content',null,'$ctime',null)";
			if($this->db->insert($sql)){
				echo "留言成功";
			}
		}
		function delMsg($id)
		{
			$sql = "delete from guest where id= $id";
			if($this->db->delete($sql))
			{
				echo "删除成功";
			}
		}
		function getMessage($id)
		{
			$sql = "select * from guest where id = $id";
			return $this->db->get($sql);
		}
		function updateMsg($data)
		{   
			
			$id = $data['id'];
			$maname = $data['maname'];
			$password = $data['password'];
			$email = $data['email'];
			$sql = "update manager set maname = '$maname',password = '$password',email='$email' where id = $id";
			if($this->db->update($sql))
			{
				return true;
			}else
			{
				return false;
			}
		}
	}
 ?>